from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt

from .models import MfNews


# Create your views here.
def handleList(request):
    return render(request, 'news.html')
    # myList = MfNews.objects.all().values('title', 'content')
    # list = []
    # for tmp in myList:
    #     list.append(tmp)
    # result = {"code": 1, "data": list}
    # return HttpResponse(json.dumps(result))


@csrf_exempt
def getlist(request):
    contact_list = MfNews.objects.all().values()
    data = list(contact_list)
    result = {"code": 1, "data": data, 'pageCount': len(data)}
    return JsonResponse(result)


# news/detail?id=1
def handleDetail(request):
    return render(request, 'news_details.html')
    # myId = request.GET['id']
    # myList = MfNews.objects.filter(id=myId).values("content", 'title', "id")
    # list = []
    # for tmp in myList:
    #     list.append(tmp)
    # if (len(list) == 0):
    #     result = {"code": 0, "data": []}
    # else:
    #     result = {"code": 1, "data": list}
    # return HttpResponse(json.dumps(result))
